package com.fengmi.mapper;

import com.fengmi.entity.SysPermission;
import com.fengmi.entity.SysRole;
import com.fengmi.entity.SysUser;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * Author: 施俊豪
 * Date: 2022/2/5 17:38
 * Note: UserMapper
 */
public interface SysUserMapper {

    // 根据用户名查询用户
    @Select("select * from sys_user where account = #{account}")
    public SysUser findUserByName(String account);

    // 获取用户的角色列表
    @Select("select sys_role.* from sys_user_role sur left join sys_role on " +
            "sur.role_id = sys_role.role_code where sur.user_id = #{userId}")
    public List<SysRole> findRolesByUserId(Integer userId);

    // 获取用户的权限列表
    @Select("SELECT\n" +
            "\tsp.* \n" +
            "FROM\n" +
            "\tsys_user_role sur\n" +
            "\tLEFT JOIN sys_role_permission srp ON sur.role_id = srp.role_id\n" +
            "\tLEFT JOIN sys_permission sp ON srp.perm_id = sp.perm_code \n" +
            "WHERE\n" +
            "\tuser_id = #{userId}")
    public List<SysPermission> findPermissionByUserId(Integer userId);
}
